/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database.mysql;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author teste
 */
public class ConnectionMySQL {
    private java.sql.Connection con = null;
    private String username = "root";
    private String password = "";
    private String databaseName = "pcs_sgbd";
    private String server = "localhost";
    
    public ConnectionMySQL(){
        this.open();
    }
    
    public ConnectionMySQL(String username, String password){
        this.username = username;
        this.password = password;
        this.open();
    }
    
    public void open(){
        String url = "jdbc:mysql://"+this.server+"/"+this.databaseName;
        
        try {
            Class.forName("com.mysql.jdbc.Driver");
            this.con = DriverManager.getConnection(url, this.username, this.password);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void close(){
        try{
            this.con.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    public java.sql.Connection getConnection(){
        return this.con;
    }
}
